package sentryLog

import (
	"account/configs"
	"log"
	"time"

	"github.com/getsentry/sentry-go"
)

// sentry 驱动

var Log *SentryLog

type SentryLog struct {
	Sentry *sentry.Hub
}

func NewSentryLog(sentry *sentry.Hub) *SentryLog {
	return &SentryLog{
		Sentry: sentry,
	}
}

func (s SentryLog) Send(message string) {
	s.Sentry.CaptureMessage(message)
}

func init() {

	sentryConfig := configs.GetSentryConfig()
	err := sentry.Init(sentry.ClientOptions{
		Dsn:         sentryConfig["DSN"].(string),
		Environment: sentryConfig["Environment"].(string),
		Release:     sentryConfig["Release"].(string),
		Debug:       sentryConfig["Debug"].(bool),
	})
	if err != nil {
		log.Fatalf("sentry.Init: %s", err)
	}
	// Flush buffered events before the program terminates.
	defer sentry.Flush(2 * time.Second)

	Log = NewSentryLog(sentry.CurrentHub().Clone())
	// SentryLog.Send("ccccccccccccccccc")
}
